import os
import sys
import time
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *


class TimeThread(QThread):
    def __init__(self):
        super(TimeThread, self).__init__()
        self.time_value=0
        self.stop=False

    def run(self):
        # now=time.time()
        while self.stop==False:
            self.time_value=time.time()
            # print(self.time_value)


class TimeTip(QWidget):
    start_Signal=pyqtSignal(int)
    def __init__(self):
        super(TimeTip, self).__init__()
        #全局变量
        self.IMG_PATH=os.path.join(os.path.dirname(os.path.dirname(__file__)),'imgs')
    
        # self.main_layout=QVBoxLayout()
        self.setMinimumHeight(800)
        self.setMinimumWidth(800)
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowMinimizeButtonHint)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.label_1=QLabel('',self)
        self.label_1.move(self.width()/2,self.height()/2)
        self.label_1.setPixmap(QPixmap(os.path.join(self.IMG_PATH,'1.png')))
        self.label_2=QLabel('',self)
        self.label_2.move(self.width()/2,self.height()/2)
        self.label_2.setPixmap(QPixmap(os.path.join(self.IMG_PATH, '2.png')))
        self.label_3=QLabel('',self)
        self.label_3.move(self.width()/2,self.height()/2)
        self.label_3.setPixmap(QPixmap(os.path.join(self.IMG_PATH, '3.png')))
        # self.addWidget(self.label_1)
        # self.addWidget(self.label_2)
        # self.addWidget(self.label_3)
        # self.init_label()
        # self.setLayout(self.main_layout)

        self._time_thread=TimeThread()
        self.timer=QBasicTimer()
        self.first_time=time.time()
        self._start()

        # self.btn=QPushButton('d',self)
        # self.btn.clicked.connect(self.hid)

    def hid(self):
        self.label_3.setHidden(True)

    def timerEvent(self, *args, **kwargs):
        if self._time_thread.time_value-self.first_time>1.5:
            self.label_3.setHidden(True)
        if self._time_thread.time_value-self.first_time>2.5:
            self.label_2.setHidden(True)
        if self._time_thread.time_value-self.first_time>3.5:
            self.label_1.setHidden(True)
            self._time_thread.stop=True
            self.start_Signal.emit(1)
            self.timer.stop()
            
            print('emit1')
            self.close()

    def _start(self):
        self.timer.start(10,self)
        self._time_thread.start()



if __name__ == '__main__':
    app=QApplication(sys.argv)
    t=TimeTip()
    t.show()
    sys.exit(app.exec_())

